powerstep2 2.2.1
Loading...
Searching...
No Matches
powerstep2


Power Step 2 Click

Power Step 2 Click demo application is developed using the NECTO Studio, ensuring compatibility with mikroSDK's open-source libraries and tools. Designed for plug-and-play implementation and testing, the demo is fully compatible with all development, starter, and mikromedia boards featuring a mikroBUS™ socket.


Click Library

  • Author : Stefan Filipovic
  • Date : Jan 2025.
  • Type : SPI type

Software Support

Example Description

This example demonstrates the use of the Power Step 2 Click board for precise control of stepper motors. The application showcases various step modes, directions, and speeds while demonstrating the board's ability to control motors using different operation modes.

Example Libraries

  • MikroSDK.Board
  • MikroSDK.Log
  • Click.PowerStep2

Example Key Functions

Application Init

Initializes the logger and configures the Power Step 2 Click board. The default settings are applied to prepare the device for motor control operations.

void application_init ( void )
{
log_cfg_t log_cfg;
powerstep2_cfg_t powerstep2_cfg;
LOG_MAP_USB_UART( log_cfg );
log_init( &logger, &log_cfg );
log_info( &logger, " Application Init " );
// Click initialization.
powerstep2_cfg_setup( &powerstep2_cfg );
if ( SPI_MASTER_ERROR == powerstep2_init( &powerstep2, &powerstep2_cfg ) )
{
log_error( &logger, " Communication init." );
for ( ; ; );
}
if ( POWERSTEP2_ERROR == powerstep2_default_cfg ( &powerstep2 ) )
{
log_error( &logger, " Default configuration." );
for ( ; ; );
}
log_info( &logger, " Application Task " );
}
#define POWERSTEP2_MAP_MIKROBUS(cfg, mikrobus)
MikroBUS pin mapping.
Definition powerstep2.h:630
void application_init(void)
Definition main.c:37
#define MIKROBUS_POSITION_POWERSTEP2
Definition main.c:31
@ POWERSTEP2_ERROR
Definition powerstep2.h:699

Application Task

Demonstrates motor control with various configurations. The example alternates between multiple step modes (1/8, 1/16, 1/32, 1/4), directions (CW, CCW), speeds, and control modes (voltage, current). Each configuration is applied sequentially, with the motor driven through specified steps before switching to the next configuration.

void application_task ( void )
{
log_printf ( &logger, " Step mode: 1/8\r\n" );
log_printf ( &logger, " Direction: CW\r\n" );
log_printf ( &logger, " Steps: 16000\r\n" );
log_printf ( &logger, " Speed: [0, 500]\r\n" );
log_printf ( &logger, " Acc-Dec: [200, 100]\r\n" );
log_printf ( &logger, " Control mode: Command voltage\r\n\n" );
powerstep2_clear_status ( &powerstep2 );
powerstep2_set_speed ( &powerstep2, 0, 500 );
powerstep2_set_acc_dec ( &powerstep2, 200, 100 );
powerstep2_move ( &powerstep2, POWERSTEP2_DIR_CW, 16000 );
powerstep2_soft_hiz ( &powerstep2 );
Delay_ms ( 1000 );
log_printf ( &logger, " Step mode: 1/16\r\n" );
log_printf ( &logger, " Direction: CCW\r\n" );
log_printf ( &logger, " Steps: 32000\r\n" );
log_printf ( &logger, " Speed: [350, 600]\r\n" );
log_printf ( &logger, " Acc-Dec: [100, 200]\r\n" );
log_printf ( &logger, " Control mode: Command current\r\n\n" );
powerstep2_clear_status ( &powerstep2 );
powerstep2_set_speed ( &powerstep2, 350, 600 );
powerstep2_set_acc_dec ( &powerstep2, 100, 200 );
powerstep2_move ( &powerstep2, POWERSTEP2_DIR_CCW, 32000 );
powerstep2_soft_hiz ( &powerstep2 );
Delay_ms ( 1000 );
log_printf ( &logger, " Step mode: 1/32\r\n" );
log_printf ( &logger, " Direction: CW\r\n" );
log_printf ( &logger, " Steps: 16000\r\n" );
log_printf ( &logger, " Speed: Very fast\r\n" );
log_printf ( &logger, " Control mode: Step-clock voltage\r\n\n" );
powerstep2_clear_status ( &powerstep2 );
powerstep2_soft_hiz ( &powerstep2 );
Delay_ms ( 1000 );
log_printf ( &logger, " Step mode: 1/4\r\n" );
log_printf ( &logger, " Direction: CCW\r\n" );
log_printf ( &logger, " Steps: 2000\r\n" );
log_printf ( &logger, " Speed: Medium\r\n" );
log_printf ( &logger, " Control mode: Step-clock current\r\n\n" );
powerstep2_clear_status ( &powerstep2 );
powerstep2_soft_hiz ( &powerstep2 );
Delay_ms ( 1000 );
}
#define POWERSTEP2_DIR_CCW
Definition powerstep2.h:578
#define POWERSTEP2_STEP_MODE_QUARTER_STEP
Definition powerstep2.h:544
#define POWERSTEP2_CONTROL_MODE_VOLTAGE
Power Step 2 control mode setting.
Definition powerstep2.h:535
#define POWERSTEP2_STEP_MODE_1_OVER_16
Definition powerstep2.h:546
#define POWERSTEP2_CONTROL_MODE_CURRENT
Definition powerstep2.h:536
#define POWERSTEP2_STEP_MODE_1_OVER_32
Definition powerstep2.h:547
#define POWERSTEP2_SPEED_MEDIUM
Definition powerstep2.h:593
#define POWERSTEP2_STEP_MODE_1_OVER_8
Definition powerstep2.h:545
#define POWERSTEP2_SPEED_VERY_FAST
Definition powerstep2.h:595
#define POWERSTEP2_DIR_CW
Power Step 2 direction setting.
Definition powerstep2.h:577
err_t powerstep2_clear_status(powerstep2_t *ctx)
Power Step 2 clear status function.
err_t powerstep2_set_control_mode(powerstep2_t *ctx, uint8_t ctrl_mode)
Power Step 2 set control mode function.
err_t powerstep2_step_clock(powerstep2_t *ctx, uint8_t dir)
Power Step 2 step clock function.
void powerstep2_drive_motor(powerstep2_t *ctx, uint32_t steps, uint8_t speed)
Power Step 2 drive motor function.
err_t powerstep2_set_acc_dec(powerstep2_t *ctx, float acc_step_s2, float dec_step_s2)
Power Step 2 set acceleration and deceleration function.
err_t powerstep2_soft_hiz(powerstep2_t *ctx)
Power Step 2 soft HiZ function.
void application_task(void)
Definition main.c:73

Application Output

This Click board can be interfaced and monitored in two ways:

  • Application Output - Use the "Application Output" window in Debug mode for real-time data monitoring. Set it up properly by following this tutorial.
  • UART Terminal - Monitor data via the UART Terminal using a USB to UART converter. For detailed instructions, check out this tutorial.

Additional Notes and Information

The complete application code and a ready-to-use project are available through the NECTO Studio Package Manager for direct installation in the NECTO Studio. The application code can also be found on the MIKROE GitHub account.